home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / shapeshifter / hardfile / utility.ss / MacZip 1.01 final.sit / MacZip 1.01 final / docs / appnote.iz < prev    next >
Text File  |  1998-11-15  |  79KB  |  1,861 lines

  1. [Info-ZIP note, 981115:  this file is based on PKWARE's appnote.txt of
  2.  15 February 1996, taking into account PKWARE's revised appnote.txt version
  3.  of 01 May 1997.  It has been unofficially corrected and extended by
  4.  Info-ZIP without explicit permission by PKWARE.  Although Info-ZIP
  5.  believes the information to be accurate and complete, it is provided
  6.  under a disclaimer similar to the PKWARE disclaimer below, differing
  7.  only in the substitution of "Info-ZIP" for "PKWARE".  In other words,
  8.  use this information at your own risk, but we think it's correct.
  9.  
  10.  Specification info from PKWARE that was obviously wrong has been corrected
  11.  silently (e.g. missing structure fields, wrong numbers
  12.  As of PKZIPW 2.50, two new incompatibilities have been introduced by PKWARE;
  13.  they are noted below.  Note that the "NTFS tag" conflict is currently not
  14.  real; PKZIPW 2.50 actually tags NTFS files as having come from a FAT
  15.  file system, too.]
  16.  
  17.  
  18. Disclaimer
  19. ----------
  20.  
  21. Although PKWARE will attempt to supply current and accurate
  22. information relating to its file formats, algorithms, and the
  23. subject programs, the possibility of error can not be eliminated.
  24. PKWARE therefore expressly disclaims any warranty that the
  25. information contained in the associated materials relating to the
  26. subject programs and/or the format of the files created or
  27. accessed by the subject programs and/or the algorithms used by
  28. the subject programs, or any other matter, is current, correct or
  29. accurate as delivered.  Any risk of damage due to any possible
  30. inaccurate information is assumed by the user of the information.
  31. Furthermore, the information relating to the subject programs
  32. and/or the file formats created or accessed by the subject
  33. programs and/or the algorithms used by the subject programs is
  34. subject to change without notice.
  35.  
  36.  
  37. General Format of a ZIP file
  38. ----------------------------
  39.  
  40.   Files stored in arbitrary order.  Large zipfiles can span multiple
  41.   diskette media.
  42.  
  43.   Overall zipfile format:
  44.  
  45.     [local file header + file data + data_descriptor] . . .
  46.     [central directory] end of central directory record
  47.  
  48.  
  49.   A.  Local file header:
  50.  
  51.         local file header signature     4 bytes  (0x04034b50)
  52.         version needed to extract       2 bytes
  53.         general purpose bit flag        2 bytes
  54.         compression method              2 bytes
  55.         last mod file time              2 bytes
  56.         last mod file date              2 bytes
  57.         crc-32                          4 bytes
  58.         compressed size                 4 bytes
  59.         uncompressed size               4 bytes
  60.         filename length                 2 bytes
  61.         extra field length              2 bytes
  62.  
  63.         filename (variable size)
  64.         extra field (variable size)
  65.  
  66.  
  67.   B.  Data descriptor:
  68.  
  69.         data descriptor signature       4 bytes  (0x08074b50)
  70.         crc-32                          4 bytes
  71.         compressed size                 4 bytes
  72.         uncompressed size               4 bytes
  73.  
  74.       This descriptor exists only if bit 3 of the general
  75.       purpose bit flag is set (see below).  It is byte aligned
  76.       and immediately follows the last byte of compressed data.
  77.       This descriptor is used only when it was not possible to
  78.       seek in the output zip file, e.g., when the output zip file
  79.       was standard output or a non seekable device.
  80.  
  81.   C.  Central directory structure:
  82.  
  83.       [file header] . . .  end of central dir record
  84.  
  85.       File header:
  86.  
  87.         central file header signature   4 bytes  (0x02014b50)
  88.         version made by                 2 bytes
  89.         version needed to extract       2 bytes
  90.         general purpose bit flag        2 bytes
  91.         compression method              2 bytes
  92.         last mod file time              2 bytes
  93.         last mod file date              2 bytes
  94.         crc-32                          4 bytes
  95.         compressed size                 4 bytes
  96.         uncompressed size               4 bytes
  97.         filename length                 2 bytes
  98.         extra field length              2 bytes
  99.         file comment length             2 bytes
  100.         disk number start               2 bytes
  101.         internal file attributes        2 bytes
  102.         external file attributes        4 bytes
  103.         relative offset of local header 4 bytes
  104.  
  105.         filename (variable size)
  106.         extra field (variable size)
  107.         file comment (variable size)
  108.  
  109.       End of central dir record:
  110.  
  111.         end of central dir signature    4 bytes  (0x06054b50)
  112.         number of this disk             2 bytes
  113.         number of the disk with the
  114.         start of the central directory  2 bytes
  115.         total number of entries in
  116.         the central dir on this disk    2 bytes
  117.         total number of entries in
  118.         the central dir                 2 bytes
  119.         size of the central directory   4 bytes
  120.         offset of start of central
  121.         directory with respect to
  122.         the starting disk number        4 bytes
  123.         zipfile comment length          2 bytes
  124.         zipfile comment (variable size)
  125.  
  126.  
  127.   D.  Explanation of fields:
  128.  
  129.       version made by (2 bytes)
  130.  
  131.           The upper byte indicates the host system (OS) for the
  132.           file.  Software can use this information to determine
  133.           the line record format for text files etc.  The current
  134.           mappings are:
  135.  
  136.           0 - FAT file system (DOS, OS/2, NT)         + PKZIPW 2.50 VFAT, NTFS
  137.           1 - Amiga
  138.           2 - VMS (VAX or Alpha AXP)
  139.           3 - Unix
  140.           4 - VM/CMS
  141.           5 - Atari
  142.           6 - HPFS file system (OS/2, NT 3.x)
  143.           7 - Macintosh
  144.           8 - Z-System
  145.           9 - CP/M
  146.           10 - TOPS-20                          [supposedly PKZIPW 2.50 NTFS]
  147.           11 - NTFS file system (NT)            [used by Info-ZIP, only]
  148.           12 - SMS/QDOS
  149.           13 - Acorn RISC OS
  150.           14 - VFAT file system (Win95, NT)     [Info-ZIP reservation, unused]
  151.           15 - MVS
  152.           16 - BeOS (BeBox or PowerMac)
  153.           17 - Tandem
  154.           18 thru 255 - unused
  155.  
  156.           The lower byte indicates the version number of the
  157.           software used to encode the file.  The value/10
  158.           indicates the major version number, and the value
  159.           mod 10 is the minor version number.
  160.  
  161.       version needed to extract (2 bytes)
  162.  
  163.           The minimum software version needed to extract the
  164.           file, mapped as above.
  165.  
  166.       general purpose bit flag: (2 bytes)
  167.  
  168.           Bit 0: If set, indicates that the file is encrypted.
  169.  
  170.           (For Method 6 - Imploding)
  171.           Bit 1: If the compression method used was type 6,
  172.                  Imploding, then this bit, if set, indicates
  173.                  an 8K sliding dictionary was used.  If clear,
  174.                  then a 4K sliding dictionary was used.
  175.           Bit 2: If the compression method used was type 6,
  176.                  Imploding, then this bit, if set, indicates
  177.                  an 3 Shannon-Fano trees were used to encode the
  178.                  sliding dictionary output.  If clear, then 2
  179.                  Shannon-Fano trees were used.
  180.  
  181.           (For Method 8 - Deflating)
  182.           Bit 2  Bit 1
  183.             0      0    Normal (-en) compression option was used.
  184.             0      1    Maximum (-ex) compression option was used.
  185.             1      0    Fast (-ef) compression option was used.
  186.             1      1    Super Fast (-es) compression option was used.
  187.  
  188.           Note:  Bits 1 and 2 are undefined if the compression
  189.                  method is any other.
  190.  
  191.           Bit 3: If this bit is set, the fields crc-32, compressed size
  192.                  and uncompressed size are set to zero in the local
  193.                  header.  The correct values are put in the data descriptor
  194.                  immediately following the compressed data.  (Note: PKZIP
  195.                  version 2.04g for DOS only recognizes this bit for method 8
  196.                  compression, newer versions of PKZIP recognize this bit
  197.                  for any compression method.)
  198.                 [Info-ZIP note: This bit was introduced by PKZIP 2.04 for
  199.                  DOS. In general, this feature can only be reliably used
  200.                  together with compression methods that allow intrinsic
  201.                  detection of the "end-of-compressed-data" condition. From
  202.                  the set of compression methods described in this Zip archive
  203.                  specification, only "deflate" meets this requirement.
  204.                  Especially, the method STORED does not work!
  205.                  The Info-ZIP tools recognize this bit regardless of the
  206.                  compression method; but, they rely on correctly set
  207.                  "compressed size" information in the central directory entry.]
  208.  
  209.           The upper three bits are reserved and used internally
  210.           by the software when processing the zipfile.  The
  211.           remaining bits are unused.
  212.  
  213.       compression method: (2 bytes)
  214.  
  215.           (see accompanying documentation for algorithm
  216.           descriptions)
  217.  
  218.           0 - The file is stored (no compression)
  219.           1 - The file is Shrunk
  220.           2 - The file is Reduced with compression factor 1
  221.           3 - The file is Reduced with compression factor 2
  222.           4 - The file is Reduced with compression factor 3
  223.           5 - The file is Reduced with compression factor 4
  224.           6 - The file is Imploded
  225.           7 - Reserved for Tokenizing compression algorithm
  226.           8 - The file is Deflated
  227.           9 - Reserved for enhanced Deflating
  228.          10 - PKWARE Data Compression Library Imploding
  229.  
  230.       date and time fields: (2 bytes each)
  231.  
  232.           The date and time are encoded in standard MS-DOS format.
  233.           If input came from standard input, the date and time are
  234.           those at which compression was started for this data.
  235.  
  236.       CRC-32: (4 bytes)
  237.  
  238.           The CRC-32 algorithm was generously contributed by
  239.           David Schwaderer and can be found in his excellent
  240.           book "C Programmers Guide to NetBIOS" published by
  241.           Howard W. Sams & Co. Inc.  The 'magic number' for
  242.           the CRC is 0xdebb20e3.  The proper CRC pre and post
  243.           conditioning is used, meaning that the CRC register
  244.           is pre-conditioned with all ones (a starting value
  245.           of 0xffffffff) and the value is post-conditioned by
  246.           taking the one's complement of the CRC residual.
  247.           If bit 3 of the general purpose flag is set, this
  248.           field is set to zero in the local header and the correct
  249.           value is put in the data descriptor and in the central
  250.           directory.
  251.  
  252.       compressed size: (4 bytes)
  253.       uncompressed size: (4 bytes)
  254.  
  255.           The size of the file compressed and uncompressed,
  256.           respectively.  If bit 3 of the general purpose bit flag
  257.           is set, these fields are set to zero in the local header
  258.           and the correct values are put in the data descriptor and
  259.           in the central directory.
  260.  
  261.       filename length: (2 bytes)
  262.       extra field length: (2 bytes)
  263.       file comment length: (2 bytes)
  264.  
  265.           The length of the filename, extra field, and comment
  266.           fields respectively.  The combined length of any
  267.           directory record and these three fields should not
  268.           generally exceed 65,535 bytes.  If input came from standard
  269.           input, the filename length is set to zero.
  270.  
  271.          [Info-ZIP note:
  272.           This feature is not yet supported by any PKWARE version of ZIP
  273.           (at least not in PKZIP for DOS and PKZIP for Windows/WinNT).
  274.           The Info-ZIP programs handle standard input differently:
  275.           If input came from standard input, the filename is set to "-"
  276.           (length one).]
  277.  
  278.  
  279.       disk number start: (2 bytes)
  280.  
  281.           The number of the disk on which this file begins.
  282.  
  283.       internal file attributes: (2 bytes)
  284.  
  285.           The lowest bit of this field indicates, if set, that
  286.           the file is apparently an ASCII or text file.  If not
  287.           set, that the file apparently contains binary data.
  288.           The remaining bits are unused in version 1.0.
  289.  
  290.       external file attributes: (4 bytes)
  291.  
  292.           The mapping of the external attributes is
  293.           host-system dependent (see 'version made by').  For
  294.           MS-DOS, the low order byte is the MS-DOS directory
  295.           attribute byte.  If input came from standard input, this
  296.           field is set to zero.
  297.  
  298.       relative offset of local header: (4 bytes)
  299.  
  300.           This is the offset from the start of the first disk on
  301.           which this file appears, to where the local header should
  302.           be found.
  303.  
  304.       filename: (Variable)
  305.  
  306.           The name of the file, with optional relative path.
  307.           The path stored should not contain a drive or
  308.           device letter, or a leading slash.  All slashes
  309.           should be forward slashes '/' as opposed to
  310.           backwards slashes '\' for compatibility with Amiga
  311.           and Unix file systems etc.  If input came from standard
  312.           input, there is no filename field.
  313.          [Info-ZIP discrepancy:
  314.           If input came from standard input, the file name is set
  315.           to "-" (without the quotes).
  316.           As far as we know, the PKWARE specification for "input from
  317.           stdin" is not supported by PKZIP/PKUNZIP for DOS, OS/2, Windows
  318.           Windows NT.]
  319.  
  320.       extra field: (Variable)
  321.  
  322.           This is for future expansion.  If additional information
  323.           needs to be stored in the future, it should be stored
  324.           here.  Earlier versions of the software can then safely
  325.           skip this file, and find the next file or header.  This
  326.           field will be 0 length in version 1.0.
  327.  
  328.           In order to allow different programs and different types
  329.           of information to be stored in the 'extra' field in .ZIP
  330.           files, the following structure should be used for all
  331.           programs storing data in this field:
  332.  
  333.           header1+data1 + header2+data2 . . .
  334.  
  335.           Each header should consist of:
  336.  
  337.             Header ID - 2 bytes
  338.             Data Size - 2 bytes
  339.  
  340.           Note: all fields stored in Intel low-byte/high-byte order.
  341.  
  342.           The Header ID field indicates the type of data that is in
  343.           the following data block.
  344.  
  345.           Header ID's of 0 thru 31 are reserved for use by PKWARE.
  346.           The remaining ID's can be used by third party vendors for
  347.           proprietary usage.
  348.  
  349.           The current Header ID mappings defined by PKWARE are:
  350.  
  351.           0x0007        AV Info
  352.           0x0009        OS/2 extended attributes      (also Info-ZIP)
  353.           0x000a        PKWARE Win95/WinNT FileTimes  [undocumented!]
  354.           0x000c        PKWARE VAX/VMS                (also Info-ZIP)
  355.           0x000d        reserved for Unix
  356.  
  357.           The Header ID mappings defined by Info-ZIP and third parties are:
  358.  
  359.           0x07c8        Info-ZIP Macintosh (old, J. Lee)
  360.           0x2605        ZipIt Macintosh (first version)
  361.           0x2705        ZipIt Macintosh v 1.3.5 and newer (w/o full filename)
  362.           0x334d        Info-ZIP Macintosh (new, D. Haase's 'Mac3' field )
  363.           0x4341        Acorn/SparkFS (David Pilling)
  364.           0x4453        Windows NT security descriptor (binary ACL)
  365.           0x4704        VM/CMS
  366.           0x470f        MVS
  367.           0x4b46        FWKCS MD5 (third party, see below)
  368.           0x4c41        OS/2 access control list (text ACL)
  369.           0x4d49        Info-ZIP VMS (VAX or Alpha)
  370.           0x5356        AOS/VS (binary ACL)
  371.           0x5455        extended timestamp
  372.           0x5855        Info-ZIP Unix (original; also OS/2, NT, etc.)
  373.           0x6542        BeOS (BeBox, PowerMac, etc.)
  374.           0x756e        ASi Unix
  375.           0x7855        Info-ZIP Unix (new)
  376.           0xfb4a        SMS/QDOS
  377.  
  378.           The Data Size field indicates the size of the following
  379.           data block. Programs can use this value to skip to the
  380.           next header block, passing over any data blocks that are
  381.           not of interest.
  382.  
  383.           Note: As stated above, the size of the entire .ZIP file
  384.                 header, including the filename, comment, and extra
  385.                 field should not exceed 64K in size.
  386.  
  387.           In case two different programs should appropriate the same
  388.           Header ID value, it is strongly recommended that each
  389.           program place a unique signature of at least two bytes in
  390.           size (and preferably 4 bytes or bigger) at the start of
  391.           each data area.  Every program should verify that its
  392.           unique signature is present, in addition to the Header ID
  393.           value being correct, before assuming that it is a block of
  394.           known type.
  395.  
  396.           In the following descriptions, note that "Short" means two bytes,
  397.           "Long" means four bytes, and "Long-Long" means eight bytes,
  398.           regardless of their native sizes.  Unless specifically noted, all
  399.           integer fields should be interpreted as unsigned (non-negative)
  400.           numbers.
  401.  
  402.  
  403.          -OS/2 Extended Attributes Extra Field:
  404.           ====================================
  405.  
  406.           The following is the layout of the OS/2 extended attributes "extra"
  407.           block.  (Last Revision 19960922)
  408.  
  409.           Note: all fields stored in Intel low-byte/high-byte order.
  410.  
  411.           Local-header version:
  412.  
  413.           Value         Size            Description
  414.           -----         ----            -----------
  415.   (OS/2)  0x0009        Short           tag for this extra block type
  416.           TSize         Short           total data size for this block
  417.           BSize         Long            uncompressed EA data size
  418.           CType         Short           compression type
  419.           EACRC         Long            CRC value for uncompressed EA data
  420.           (var.)        variable        compressed EA data
  421.  
  422.           Central-header version:
  423.  
  424.           Value         Size            Description
  425.           -----         ----            -----------
  426.   (OS/2)  0x0009        Short           tag for this extra block type
  427.           TSize         Short           total data size for this block
  428.           BSize         Long            size of uncompressed local EA data
  429.  
  430.           The value of CType is interpreted according to the "compression
  431.           method" section above; i.e., 0 for stored, 8 for deflated, etc.
  432.  
  433.           The OS/2 extended attribute structure (FEA2LIST) is compressed and
  434.           then stored in its entirety within this structure.  There will only
  435.           ever be one block of data in the variable-length field.
  436.  
  437.  
  438.          -OS/2 Access Control List Extra Field:
  439.           ====================================
  440.  
  441.           The following is the layout of the OS/2 ACL extra block.
  442.           (Last Revision 19960922)
  443.  
  444.           Local-header version:
  445.  
  446.           Value         Size            Description
  447.           -----         ----            -----------
  448.   (ACL)   0x4c41        Short           tag for this extra block type
  449.           TSize         Short           total data size for this block
  450.           BSize         Long            uncompressed ACL data size
  451.           CType         Short           compression type
  452.           EACRC         Long            CRC value for uncompressed ACL data
  453.           (var.)        variable        compressed ACL data
  454.  
  455.           Central-header version:
  456.  
  457.           Value         Size            Description
  458.           -----         ----            -----------
  459.   (ACL)   0x4c41        Short           tag for this extra block type
  460.           TSize         Short           total data size for this block
  461.           BSize         Long            size of uncompressed local ACL data
  462.  
  463.           The value of CType is interpreted according to the "compression
  464.           method" section above; i.e., 0 for stored, 8 for deflated, etc.
  465.  
  466.           The uncompressed ACL data consist of a text header of the form
  467.           "ACL1:%hX,%hd\n", where the first field is the OS/2 ACCINFO acc_attr
  468.           member and the second is acc_count, followed by acc_count strings
  469.           of the form "%s,%hx\n", where the first field is acl_ugname (user
  470.           group name) and the second acl_access.  This block type will be
  471.           extended for other operating systems as needed.
  472.  
  473.  
  474.          -Windows NT Security Descriptor Extra Field:
  475.           ==========================================
  476.  
  477.           The following is the layout of the NT Security Descriptor (another
  478.           type of ACL) extra block.  (Last Revision 19960922)
  479.  
  480.           Local-header version:
  481.  
  482.           Value         Size            Description
  483.           -----         ----            -----------
  484.   (SD)    0x4453        Short           tag for this extra block type
  485.           TSize         Short           total data size for this block
  486.           BSize         Long            uncompressed SD data size
  487.           Version       Byte            version of uncompressed SD data format
  488.           CType         Short           compression type
  489.           EACRC         Long            CRC value for uncompressed SD data
  490.           (var.)        variable        compressed SD data
  491.  
  492.           Central-header version:
  493.  
  494.           Value         Size            Description
  495.           -----         ----            -----------
  496.   (SD)    0x4453        Short           tag for this extra block type
  497.           TSize         Short           total data size for this block
  498.           BSize         Long            size of uncompressed local SD data
  499.  
  500.           The value of CType is interpreted according to the "compression
  501.           method" section above; i.e., 0 for stored, 8 for deflated, etc.
  502.           Version specifies how the compressed data are to be interpreted
  503.           and allows for future expansion of this extra field type.  Currently
  504.           only version 0 is defined.
  505.  
  506.           For version 0, the compressed data are to be interpreted as a single
  507.           valid Windows NT SECURITY_DESCRIPTOR data structure, in self-relative
  508.           format.
  509.  
  510.  
  511.          -PKWARE Win95/WinNT Extra Field:
  512.           ==============================
  513.  
  514.           The following description covers PKWARE's undocumented
  515.           Windows 95 & Windows NT extra field, introduced with the
  516.           release of PKZIP for Windows 2.50. (Last Revision 19980425)
  517.  
  518.           This field has a fixed data size of 32 bytes and is only stored
  519.           as local extra field.
  520.  
  521.           Value         Size            Description
  522.           -----         ----            -----------
  523.  (WinNT)  0x000a        Short           Tag for this "extra" block type
  524.           TSize         Short           Total Data Size for this block
  525.           Unknwn1       Long            ???? (all 0 ?)
  526.           Unknwn2       Long            ????
  527.           ModTime       Long-Long       64-bit NTFS last-modified filetime
  528.           AccTime       Long-Long       64-bit NTFS last-access filetime
  529.           CreTime       Long-Long       64-bit NTFS creation filetime
  530.  
  531.           The NTFS filetimes are 64-bit unsigned integers, stored in Intel
  532.           (least significant byte first) byte order. They determine the
  533.           number of 1.0E-07 seconds (1/10th microseconds!) past WinNT "epoch",
  534.           which is "01-Jan-1601 00:00:00 UTC".
  535.  
  536.  
  537.          -PKWARE VAX/VMS Extra Field:
  538.           ==========================
  539.  
  540.           The following is the layout of PKWARE's VAX/VMS attributes "extra"
  541.           block.  (Last Revision 12/17/91)
  542.  
  543.           Note: all fields stored in Intel low-byte/high-byte order.
  544.  
  545.           Value         Size            Description
  546.           -----         ----            -----------
  547.   (VMS)   0x000c        Short           Tag for this "extra" block type
  548.           TSize         Short           Total Data Size for this block
  549.           CRC           Long            32-bit CRC for remainder of the block
  550.           Tag1          Short           VMS attribute tag value #1
  551.           Size1         Short           Size of attribute #1, in bytes
  552.           (var.)        Size1           Attribute #1 data
  553.           .
  554.           .
  555.           .
  556.           TagN          Short           VMS attribute tage value #N
  557.           SizeN         Short           Size of attribute #N, in bytes
  558.           (var.)        SizeN           Attribute #N data
  559.  
  560.           Rules:
  561.  
  562.           1. There will be one or more of attributes present, which will
  563.              each be preceded by the above TagX & SizeX values.  These
  564.              values are identical to the ATR$C_XXXX and ATR$S_XXXX constants
  565.              which are defined in ATR.H under VMS C.  Neither of these values
  566.              will ever be zero.
  567.  
  568.           2. No word alignment or padding is performed.
  569.  
  570.           3. A well-behaved PKZIP/VMS program should never produce more than
  571.              one sub-block with the same TagX value.  Also, there will never
  572.              be more than one "extra" block of type 0x000c in a particular
  573.              directory record.
  574.  
  575.  
  576.          -Info-ZIP VMS Extra Field:
  577.           ========================
  578.  
  579.           The following is the layout of Info-ZIP's VMS attributes extra
  580.           block for VAX or Alpha AXP.  The local-header and central-header
  581.           versions are identical.  (Last Revision 19960922)
  582.  
  583.           Value         Size            Description
  584.           -----         ----            -----------
  585.   (VMS2)  0x4d49        Short           tag for this extra block type
  586.           TSize         Short           total data size for this block
  587.           ID            Long            block ID
  588.           Flags         Short           info bytes
  589.           BSize         Short           uncompressed block size
  590.           Reserved      Long            (reserved)
  591.           (var.)        variable        compressed VMS file-attributes block
  592.  
  593.           The block ID is one of the following unterminated strings:
  594.  
  595.                 "VFAB"          struct FAB
  596.                 "VALL"          struct XABALL
  597.                 "VFHC"          struct XABFHC
  598.                 "VDAT"          struct XABDAT
  599.                 "VRDT"          struct XABRDT
  600.                 "VPRO"          struct XABPRO
  601.                 "VKEY"          struct XABKEY
  602.                 "VMSV"          version (e.g., "V6.1"; truncated at hyphen)
  603.                 "VNAM"          reserved
  604.  
  605.           The lower three bits of Flags indicate the compression method.  The
  606.           currently defined methods are:
  607.  
  608.                 0       stored (not compressed)
  609.                 1       simple "RLE"
  610.                 2       deflated
  611.  
  612.           The "RLE" method simply replaces zero-valued bytes with zero-valued
  613.           bits and non-zero-valued bytes with a "1" bit followed by the byte
  614.           value.
  615.  
  616.           The variable-length compressed data contains only the data corre-
  617.           sponding to the indicated structure or string.  Typically multiple
  618.           VMS2 extra fields are present (each with a unique block type).
  619.  
  620.  
  621.          -Info-ZIP Macintosh Extra Field:
  622.           ==============================
  623.  
  624.           The following is the layout of the (old) Info-ZIP resource-fork extra
  625.           block for Macintosh.  The local-header and central-header versions
  626.           are identical.  (Last Revision 19960922)
  627.  
  628.           Value         Size            Description
  629.           -----         ----            -----------
  630.   (Mac)   0x07c8        Short           tag for this extra block type
  631.           TSize         Short           total data size for this block
  632.           "JLEE"        beLong          extra-field signature
  633.           FInfo         16 bytes        Macintosh FInfo structure
  634.           CrDat         beLong          HParamBlockRec fileParam.ioFlCrDat
  635.           MdDat         beLong          HParamBlockRec fileParam.ioFlMdDat
  636.           Flags         beLong          info bits
  637.           DirID         beLong          HParamBlockRec fileParam.ioDirID
  638.           VolName       28 bytes        volume name (optional)
  639.  
  640.           All fields but the first two are in native Macintosh format
  641.           (big-endian Motorola order, not little-endian Intel).  The least
  642.           significant bit of Flags is 1 if the file is a data fork, 0 other-
  643.           wise.  In addition, if this extra field is present, the filename
  644.           has an extra 'd' or 'r' appended to indicate data fork or resource
  645.           fork.  The 28-byte VolName field may be omitted.
  646.  
  647.  
  648.          -ZipIt Macintosh Extra Field (long):
  649.           ==================================
  650.  
  651.           The following is the layout of the ZipIt extra block for Macintosh.
  652.           The local-header and central-header versions are identical.
  653.           (Last Revision 19970130)
  654.  
  655.           Value         Size            Description
  656.           -----         ----            -----------
  657.   (Mac2)  0x2605        Short           tag for this extra block type
  658.           TSize         Short           total data size for this block
  659.           "ZPIT"        beLong          extra-field signature
  660.           FnLen         Byte            length of FileName
  661.           FileName      variable        full Macintosh filename
  662.           FileType      Byte[4]         four-byte Mac file type string
  663.           Creator       Byte[4]         four-byte Mac creator string
  664.  
  665.  
  666.          -ZipIt Macintosh Extra Field (short):
  667.           ===================================
  668.  
  669.           The following is the layout of a shortened variant of the
  670.           ZipIt extra block for Macintosh (without "full name" entry).
  671.           This variant is used by ZipIt 1.3.5 and newer for entries that
  672.           do not need a "full Mac filename" record.
  673.           The local-header and central-header versions are identical.
  674.           (Last Revision 19980903)
  675.  
  676.           Value         Size            Description
  677.           -----         ----            -----------
  678.   (Mac2b) 0x2705        Short           tag for this extra block type
  679.           TSize         Short           total data size for this block
  680.           "ZPIT"        beLong          extra-field signature
  681.           FileType      Byte[4]         four-byte Mac file type string
  682.           Creator       Byte[4]         four-byte Mac creator string
  683.  
  684.  
  685.          -Info-ZIP Macintosh Extra Field (new):
  686.           ====================================
  687.  
  688.           The following is the layout of the (new) Info-ZIP extra
  689.           block for Macintosh, designed by Dirk Haase.
  690.           All values are in little-endian.
  691.           (Last Revision 19981005)
  692.  
  693.           Local-header version:
  694.  
  695.           Value         Size            Description
  696.           -----         ----            -----------
  697.   (Mac3)  0x334d        Short           tag for this extra block type ("M3")
  698.           TSize         Short           total data size for this block
  699.           BSize         Long            uncompressed finder attribute data size
  700.           Flags         Short           info bits
  701.           fdType        Byte[4]         Type of the File (4-byte string)
  702.           fdCreator     Byte[4]         Creator of the File (4-byte string)
  703.           (CType)       Short           compression type
  704.           (CRC)         Long            CRC value for uncompressed MacOS data
  705.           Attribs       variable        finder attribute data (see below)
  706.  
  707.  
  708.           Central-header version:
  709.  
  710.           Value         Size            Description
  711.           -----         ----            -----------
  712.   (Mac3)  0x334d        Short           tag for this extra block type ("M3")
  713.           TSize         Short           total data size for this block
  714.           BSize         Long            uncompressed finder attribute data size
  715.           Flags         Short           info bits
  716.           fdType        Byte[4]         Type of the File (4-byte string)
  717.           fdCreator     Byte[4]         Creator of the File (4-byte string)
  718.  
  719.           The third bit of Flags in both headers indicates whether
  720.           the LOCAL extra field is uncompressed (and therefore whether CType
  721.           and CRC are omitted):
  722.  
  723.           Bits of the Flags:
  724.               bit 0           if set, file is a data fork; otherwise unset
  725.               bit 1           if set, filename will be not changed
  726.               bit 2           if set, Attribs is uncompressed (no CType, CRC)
  727.               bit 3           if set, date and times are in 64 bit
  728.                               if zero date and times are in 32 bit.
  729.               bit 4           if set, timezone offsets fields for the native
  730.                               Mac times are omitted (UTC support deactivated)
  731.               bits 5-15       reserved;
  732.  
  733.  
  734.           Attributes:
  735.  
  736.           Attribs is a Mac-specific block of data in little-endian format with
  737.           the following structure (if compressed, uncompress it first):
  738.  
  739.           Value         Size            Description
  740.           -----         ----            -----------
  741.           fdFlags       Short           Finder Flags
  742.           fdLocation.v  Short           Finder Icon Location
  743.           fdLocation.h  Short           Finder Icon Location
  744.           fdFldr        Short           Folder containing file
  745.  
  746.           FXInfo        16 bytes        Macintosh FXInfo structure
  747.             FXInfo-Structure:
  748.                 fdIconID        Short
  749.                 fdUnused[3]     Short       unused but reserved 6 bytes
  750.                 fdScript        Byte        Script flag and number
  751.                 fdXFlags        Byte        More flag bits
  752.                 fdComment       Short       Comment ID
  753.                 fdPutAway       Long        Home Dir ID
  754.  
  755.           FVersNum      Byte            file version number
  756.                                         may be not used by MacOS
  757.           ACUser        Byte            directory access rights
  758.  
  759.           FlCrDat       ULong           date and time of creation
  760.           FlMdDat       ULong           date and time of last modification
  761.           FlBkDat       ULong           date and time of last backup
  762.             These time numbers are original Mac FileTime values (local time!).
  763.             Currently, date-time width is 32-bit, but future version may
  764.             support be 64-bit times (see flags)
  765.  
  766.           CrGMTOffs     Long(signed!)   difference "local Creat. time - UTC"
  767.           MdGMTOffs     Long(signed!)   difference "local Modif. time - UTC"
  768.           BkGMTOffs     Long(signed!)   difference "local Backup time - UTC"
  769.             These "local time - UTC" differences (stored in seconds) may be
  770.             used to support timestamp adjustment after inter-timezone transfer.
  771.             These fields are optional; bit 4 of the flags word controls their
  772.             presence.
  773.  
  774.           Charset       Short           TextEncodingBase (Charset)
  775.                                         valid for the following two fields
  776.  
  777.           FullPath      variable        Path of the current file.
  778.                                         Zero terminated string (C-String)
  779.                                         Currently coded in the native Charset.
  780.  
  781.           Comment       variable        Finder Comment of the current file.
  782.                                         Zero terminated string (C-String)
  783.                                         Currently coded in the native Charset.
  784.  
  785.  
  786.          -Acorn SparkFS Extra Field:
  787.           =========================
  788.  
  789.           The following is the layout of David Pilling's SparkFS extra block
  790.           for Acorn RISC OS.  The local-header and central-header versions are
  791.           identical.  (Last Revision 19960922)
  792.  
  793.           Value         Size            Description
  794.           -----         ----            -----------
  795.   (Acorn) 0x4341        Short           tag for this extra block type
  796.           TSize         Short           total data size for this block
  797.           "ARC0"        Long            extra-field signature
  798.           LoadAddr      Long            load address or file type
  799.           ExecAddr      Long            exec address
  800.           Attr          Long            file permissions
  801.           Zero          Long            reserved; always zero
  802.  
  803.           The following bits of Attr are associated with the given file
  804.           permissions:
  805.  
  806.                 bit 0           user-writable ('W')
  807.                 bit 1           user-readable ('R')
  808.                 bit 2           reserved
  809.                 bit 3           locked ('L')
  810.                 bit 4           publicly writable ('w')
  811.                 bit 5           publicly readable ('r')
  812.                 bit 6           reserved
  813.                 bit 7           reserved
  814.  
  815.  
  816.          -VM/CMS Extra Field:
  817.           ==================
  818.  
  819.           The following is the layout of the file-attributes extra block for
  820.           VM/CMS.  The local-header and central-header versions are
  821.           identical.  (Last Revision 19960922)
  822.  
  823.           Value         Size            Description
  824.           -----         ----            -----------
  825.  (VM/CMS) 0x4704        Short           tag for this extra block type
  826.           TSize         Short           total data size for this block
  827.           flData        variable        file attributes data
  828.  
  829.           flData is an uncompressed fldata_t struct.
  830.  
  831.  
  832.          -MVS Extra Field:
  833.           ===============
  834.  
  835.           The following is the layout of the file-attributes extra block for
  836.           MVS.  The local-header and central-header versions are identical.
  837.           (Last Revision 19960922)
  838.  
  839.           Value         Size            Description
  840.           -----         ----            -----------
  841.   (MVS)   0x470f        Short           tag for this extra block type
  842.           TSize         Short           total data size for this block
  843.           flData        variable        file attributes data
  844.  
  845.           flData is an uncompressed fldata_t struct.
  846.  
  847.  
  848.          -PKWARE Unix Extra Field:
  849.           ========================
  850.  
  851.           The following description covers PKWARE's undocumented
  852.           Unix extra field, introduced with the release of
  853.           PKZIP for Unix 2.50. (Last Revision 19980901)
  854.  
  855.           This field has a fixed data size of 12 bytes and is only stored
  856.           as local extra field.
  857.  
  858.           Value         Size            Description
  859.           -----         ----            -----------
  860.  (Unix0)  0x000d        Short           Tag for this "extra" block type
  861.           TSize         Short           Total Data Size for this block
  862.           ModTime       Long            time of last modification (UTC/GMT)
  863.           AcTime        Long            time of last access (UTC/GMT)
  864.           UID           Short           Unix user ID
  865.           GID           Short           Unix group ID
  866.  
  867.           This field has exactly the same layout as Info-ZIP's
  868.           abandoned "Unix1 timestamps & owner ID info" extra field;
  869.           only the two tag bytes are different.
  870.  
  871.  
  872.          -Extended Timestamp Extra Field:
  873.           ==============================
  874.  
  875.           The following is the layout of the extended-timestamp extra block.
  876.           (Last Revision 19970118)
  877.  
  878.           Local-header version:
  879.  
  880.           Value         Size            Description
  881.           -----         ----            -----------
  882.   (time)  0x5455        Short           tag for this extra block type
  883.           TSize         Short           total data size for this block
  884.           Flags         Byte            info bits
  885.           (ModTime)     Long            time of last modification (UTC/GMT)
  886.           (AcTime)      Long            time of last access (UTC/GMT)
  887.           (CrTime)      Long            time of original creation (UTC/GMT)
  888.  
  889.           Central-header version:
  890.  
  891.           Value         Size            Description
  892.           -----         ----            -----------
  893.   (time)  0x5455        Short           tag for this extra block type
  894.           TSize         Short           total data size for this block
  895.           Flags         Byte            info bits (refers to local header!)
  896.           (ModTime)     Long            time of last modification (UTC/GMT)
  897.  
  898.           The central-header extra field contains the modification time only,
  899.           or no timestamp at all.  TSize is used to flag its presence or
  900.           absence.  But note:
  901.  
  902.               If "Flags" indicates that Modtime is present in the local header
  903.               field, it MUST be present in the central header field, too!
  904.               This correspondence is required because the modification time
  905.               value may be used to support trans-timezone freshening and
  906.               updating operations with zip archives.
  907.  
  908.           The time values are in standard Unix signed-long format, indicating
  909.           the number of seconds since 1 January 1970 00:00:00.  The times
  910.           are relative to Coordinated Universal Time (UTC), also sometimes
  911.           referred to as Greenwich Mean Time (GMT).  To convert to local time,
  912.           the software must know the local timezone offset from UTC/GMT.
  913.  
  914.           The lower three bits of Flags in both headers indicate which time-
  915.           stamps are present in the LOCAL extra field:
  916.  
  917.                 bit 0           if set, modification time is present
  918.                 bit 1           if set, access time is present
  919.                 bit 2           if set, creation time is present
  920.                 bits 3-7        reserved for additional timestamps; not set
  921.  
  922.           Those times that are present will appear in the order indicated, but
  923.           any combination of times may be omitted.  (Creation time may be
  924.           present without access time, for example.)  TSize should equal
  925.           (1 + 4*(number of set bits in Flags)), as the block is currently
  926.           defined.  Other timestamps may be added in the future.
  927.  
  928.  
  929.          -Info-ZIP Unix Extra Field (type 1):
  930.           ==================================
  931.  
  932.           The following is the layout of the old Info-ZIP extra block for
  933.           Unix.  It has been replaced by the extended-timestamp extra block
  934.           (0x5455) and the Unix type 2 extra block (0x7855).
  935.           (Last Revision 19970118)
  936.  
  937.           Local-header version:
  938.  
  939.           Value         Size            Description
  940.           -----         ----            -----------
  941.   (Unix1) 0x5855        Short           tag for this extra block type
  942.           TSize         Short           total data size for this block
  943.           ModTime       Long            time of last modification (UTC/GMT)
  944.           AcTime        Long            time of last access (UTC/GMT)
  945.           UID           Short           Unix user ID
  946.           GID           Short           Unix group ID
  947.  
  948.           Central-header version:
  949.  
  950.           Value         Size            Description
  951.           -----         ----            -----------
  952.   (Unix1) 0x5855        Short           tag for this extra block type
  953.           TSize         Short           total data size for this block
  954.           ModTime       Long            time of last modification (GMT/UTC)
  955.           AcTime        Long            time of last access (GMT/UTC)
  956.  
  957.           The file modification and access times are in standard Unix signed-
  958.           long format, indicating the number of seconds since 1 January 1970
  959.           00:00:00.  The times are relative to Coordinated Universal Time
  960.           (UTC), also sometimes referred to as Greenwich Mean Time (GMT).  To
  961.           convert to local time, the software must know the local timezone
  962.           offset from UTC/GMT.  The modification time may be used by non-Unix
  963.           systems to support inter-timezone freshening and updating of zip
  964.           archives.
  965.  
  966.           The local-header extra block may optionally contain UID and GID
  967.           info for the file.  The local-header TSize value is the only
  968.           indication of this.  Note that Unix UIDs and GIDs are usually
  969.           specific to a particular machine, and they generally require root
  970.           access to restore.
  971.  
  972.           This extra field type is obsolete, but it has been in use since
  973.           mid-1994.  Therefore future archiving software should continue to
  974.           support it.  Some guidelines:
  975.  
  976.               An archive member should either contain the old "Unix1"
  977.               extra field block or the new extra field types "time" and/or
  978.               "Unix2".
  979.  
  980.               If both the old "Unix1" block type and one or both of the new
  981.               block types "time" and "Unix2" are found, the "Unix1" block
  982.               should be considered invalid and ignored.
  983.  
  984.               Unarchiving software should recognize both old and new extra
  985.               field block types, but the info from new types overrides the
  986.               old "Unix1" field.
  987.  
  988.               Archiving software should recognize "Unix1" extra fields for
  989.               timestamp comparison but never create it for updated, freshened
  990.               or new archive members.  When copying existing members to a new
  991.               archive, any "Unix1" extra field blocks should be converted to
  992.               the new "time" and/or "Unix2" types.
  993.  
  994.  
  995.          -Info-ZIP Unix Extra Field (type 2):
  996.           ==================================
  997.  
  998.           The following is the layout of the new Info-ZIP extra block for
  999.           Unix.  (Last Revision 19960922)
  1000.  
  1001.           Local-header version:
  1002.  
  1003.           Value         Size            Description
  1004.           -----         ----            -----------
  1005.   (Unix2) 0x7855        Short           tag for this extra block type
  1006.           TSize         Short           total data size for this block
  1007.           UID           Short           Unix user ID
  1008.           GID           Short           Unix group ID
  1009.  
  1010.           Central-header version:
  1011.  
  1012.           Value         Size            Description
  1013.           -----         ----            -----------
  1014.   (Unix2) 0x7855        Short           tag for this extra block type
  1015.           TSize         Short           total data size for this block
  1016.  
  1017.           The data size of the central-header version is zero; it is used
  1018.           solely as a flag that UID/GID info is present in the local-header
  1019.           extra field.  If additional fields are ever added to the local
  1020.           version, the central version may be extended to indicate this.
  1021.  
  1022.           Note that Unix UIDs and GIDs are usually specific to a particular
  1023.           machine, and they generally require root access to restore.
  1024.  
  1025.  
  1026.          -ASi Unix Extra Field:
  1027.           ====================
  1028.  
  1029.           The following is the layout of the ASi extra block for Unix.  The
  1030.           local-header and central-header versions are identical.
  1031.           (Last Revision 19960916)
  1032.  
  1033.           Value         Size            Description
  1034.           -----         ----            -----------
  1035.   (Unix3) 0x756e        Short           tag for this extra block type
  1036.           TSize         Short           total data size for this block
  1037.           CRC           Long            CRC-32 of the remaining data
  1038.           Mode          Short           file permissions
  1039.           SizDev        Long            symlink'd size OR major/minor dev num
  1040.           UID           Short           user ID
  1041.           GID           Short           group ID
  1042.           (var.)        variable        symbolic link filename
  1043.  
  1044.           Mode is the standard Unix st_mode field from struct stat, containing
  1045.           user/group/other permissions, setuid/setgid and symlink info, etc.
  1046.  
  1047.           If Mode indicates that this file is a symbolic link, SizDev is the
  1048.           size of the file to which the link points.  Otherwise, if the file
  1049.           is a device, SizDev contains the standard Unix st_rdev field from
  1050.           struct stat (includes the major and minor numbers of the device).
  1051.           SizDev is undefined in other cases.
  1052.  
  1053.           If Mode indicates that the file is a symbolic link, the final field
  1054.           will be the name of the file to which the link points.  The file-
  1055.           name length can be inferred from TSize.
  1056.  
  1057.           [Note that TSize may incorrectly refer to the data size not counting
  1058.            the CRC; i.e., it may be four bytes too small.]
  1059.  
  1060.  
  1061.          -BeOS Extra Field:
  1062.           ================
  1063.  
  1064.           The following is the layout of the file-attributes extra block for
  1065.           BeOS.  (Last Revision 19970531)
  1066.  
  1067.           Local-header version:
  1068.  
  1069.           Value         Size            Description
  1070.           -----         ----            -----------
  1071.   (BeOS)  0x6542        Short           tag for this extra block type
  1072.           TSize         Short           total data size for this block
  1073.           BSize         Long            uncompressed file attribute data size
  1074.           Flags         Byte            info bits
  1075.           (CType)       Short           compression type
  1076.           (CRC)         Long            CRC value for uncompressed file attribs
  1077.           Attribs       variable        file attribute data
  1078.  
  1079.           Central-header version:
  1080.  
  1081.           Value         Size            Description
  1082.           -----         ----            -----------
  1083.   (BeOS)  0x6542        Short           tag for this extra block type
  1084.           TSize         Short           total data size for this block
  1085.           BSize         Long            size of uncompressed local EF block data
  1086.           Flags         Byte            info bits
  1087.  
  1088.           The least significant bit of Flags in both headers indicates whether
  1089.           the LOCAL extra field is uncompressed (and therefore whether CType
  1090.           and CRC are omitted):
  1091.  
  1092.                 bit 0           if set, Attribs is uncompressed (no CType, CRC)
  1093.                 bits 1-7        reserved; if set, assume error or unknown data
  1094.  
  1095.           Currently the only supported compression types are deflated (type 8)
  1096.           and stored (type 0); the latter is not used by Info-ZIP's Zip but is
  1097.           supported by UnZip.
  1098.  
  1099.           Attribs is a BeOS-specific block of data in big-endian format with
  1100.           the following structure (if compressed, uncompress it first):
  1101.  
  1102.               Value     Size            Description
  1103.               -----     ----            -----------
  1104.               Name      variable        attribute name (null-terminated string)
  1105.               Type      Long            attribute type (32-bit unsigned integer)
  1106.               Size      Long Long       data size for this sub-block (64 bits)
  1107.               Data      variable        attribute data
  1108.  
  1109.           The attribute structure is repeated for every attribute.  The Data
  1110.           field may contain anything--text, flags, bitmaps, etc.
  1111.  
  1112.  
  1113.          -SMS/QDOS Extra Field:
  1114.           ====================
  1115.  
  1116.           The following is the layout of the file-attributes extra block for
  1117.           SMS/QDOS.  The local-header and central-header versions are identical.
  1118.           (Last Revision 19960929)
  1119.  
  1120.           Value         Size            Description
  1121.           -----         ----            -----------
  1122.   (QDOS)  0xfb4a        Short           tag for this extra block type
  1123.           TSize         Short           total data size for this block
  1124.           LongID        Long            extra-field signature
  1125.           (ExtraID)     Long            additional signature/flag bytes
  1126.           QDirect       64 bytes        qdirect structure
  1127.  
  1128.           LongID may be "QZHD" or "QDOS".  In the latter case, ExtraID will
  1129.           be present.  Its first three bytes are "02\0"; the last byte is
  1130.           currently undefined.
  1131.  
  1132.           QDirect contains the file's uncompressed directory info (qdirect
  1133.           struct).  Its elements are in native (big-endian) format:
  1134.  
  1135.           d_length      beLong          file length
  1136.           d_access      byte            file access type
  1137.           d_type        byte            file type
  1138.           d_datalen     beLong          data length
  1139.           d_reserved    beLong          unused
  1140.           d_szname      beShort         size of filename
  1141.           d_name        36 bytes        filename
  1142.           d_update      beLong          time of last update
  1143.           d_refdate     beLong          file version number
  1144.           d_backup      beLong          time of last backup (archive date)
  1145.  
  1146.  
  1147.          -AOS/VS Extra Field:
  1148.           ==================
  1149.  
  1150.           The following is the layout of the extra block for Data General
  1151.           AOS/VS.  The local-header and central-header versions are identical.
  1152.           (Last Revision 19961125)
  1153.  
  1154.           Value         Size            Description
  1155.           -----         ----            -----------
  1156.   (AOSVS) 0x5356        Short           tag for this extra block type
  1157.           TSize         Short           total data size for this block
  1158.           "FCI\0"       Long            extra-field signature
  1159.           Version       Byte            version of AOS/VS extra block (10 = 1.0)
  1160.           Fstat         variable        fstat packet
  1161.           AclBuf        variable        raw ACL data ($MXACL bytes)
  1162.  
  1163.           Fstat contains the file's uncompressed fstat packet, which is one of
  1164.           the following:
  1165.  
  1166.                 normal fstat packet             (P_FSTAT struct)
  1167.                 DIR/CPD fstat packet            (P_FSTAT_DIR struct)
  1168.                 unit (device) fstat packet      (P_FSTAT_UNIT struct)
  1169.                 IPC file fstat packet           (P_FSTAT_IPC struct)
  1170.  
  1171.           AclBuf contains the raw ACL data; its length is $MXACL.
  1172.  
  1173.  
  1174.          -FWKCS MD5 Extra Field:
  1175.           =====================
  1176.  
  1177.           The following is the layout of the optional extra block used by the
  1178.           FWKCS utility.  There is no local-header version; the following
  1179.           applies only to the central header.  (Last Revision 19961207)
  1180.  
  1181.           Central-header version:
  1182.  
  1183.           Value         Size            Description
  1184.           -----         ----            -----------
  1185.   (MD5)   0x4b46        Short           tag for this extra block type
  1186.           TSize         Short           total data size for this block (19)
  1187.           "MD5"         3 bytes         extra-field signature
  1188.           MD5hash       16 bytes        128-bit MD5 hash of uncompressed data
  1189.  
  1190.           The MD5 hash in this extra block is used to automatically identify
  1191.           files independent of their filenames; it is an an enhanced contents-
  1192.           signature.
  1193.  
  1194.           FWKCS provides an option to strip this extra field, if
  1195.           present, from a zipfile central directory. In adding
  1196.           this extra field, FWKCS preserves Zipfile Authenticity
  1197.           Verification; if stripping this extra field, FWKCS
  1198.           preserves all versions of AV through PKZIP version 2.04g.
  1199.  
  1200.           ``The MD5 algorithm is being placed in the public domain for review
  1201.           and possible adoption as a standard.'' (Ron Rivest, MIT Laboratory
  1202.           for Computer Science and RSA Data Security, Inc., April 1992, RFC
  1203.           1321, 11.76-77).  FWKCS, and FWKCS Contents_Signature System, are
  1204.           trademarks of Frederick W. Kantor.
  1205.  
  1206.  
  1207.  
  1208.       file comment: (Variable)
  1209.  
  1210.           The comment for this file.
  1211.  
  1212.       number of this disk: (2 bytes)
  1213.  
  1214.           The number of this disk, which contains central
  1215.           directory end record.
  1216.  
  1217.       number of the disk with the start of the central directory: (2 bytes)
  1218.  
  1219.           The number of the disk on which the central
  1220.           directory starts.
  1221.  
  1222.       total number of entries in the central dir on this disk: (2 bytes)
  1223.  
  1224.           The number of central directory entries on this disk.
  1225.  
  1226.       total number of entries in the central dir: (2 bytes)
  1227.  
  1228.           The total number of files in the zipfile.
  1229.  
  1230.  
  1231.       size of the central directory: (4 bytes)
  1232.  
  1233.           The size (in bytes) of the entire central directory.
  1234.  
  1235.       offset of start of central directory with respect to
  1236.       the starting disk number:  (4 bytes)
  1237.  
  1238.           Offset of the start of the central directory on the
  1239.           disk on which the central directory starts.
  1240.  
  1241.       zipfile comment length: (2 bytes)
  1242.  
  1243.           The length of the comment for this zipfile.
  1244.  
  1245.       zipfile comment: (Variable)
  1246.  
  1247.           The comment for this zipfile.
  1248.  
  1249.  
  1250.   D.  General notes:
  1251.  
  1252.       1)  All fields unless otherwise noted are unsigned and stored
  1253.           in Intel low-byte:high-byte, low-word:high-word order.
  1254.  
  1255.       2)  String fields are not null terminated, since the
  1256.           length is given explicitly.
  1257.  
  1258.       3)  Local headers should not span disk boundaries.  Also, even
  1259.           though the central directory can span disk boundaries, no
  1260.           single record in the central directory should be split
  1261.           across disks.
  1262.  
  1263.       4)  The entries in the central directory may not necessarily
  1264.           be in the same order that files appear in the zipfile.
  1265.  
  1266. UnShrinking - Method 1
  1267. ----------------------
  1268.  
  1269. Shrinking is a Dynamic Ziv-Lempel-Welch compression algorithm
  1270. with partial clearing.  The initial code size is 9 bits, and
  1271. the maximum code size is 13 bits.  Shrinking differs from
  1272. conventional Dynamic Ziv-Lempel-Welch implementations in several
  1273. respects:
  1274.  
  1275. 1)  The code size is controlled by the compressor, and is not
  1276.     automatically increased when codes larger than the current
  1277.     code size are created (but not necessarily used).  When
  1278.     the decompressor encounters the code sequence 256
  1279.     (decimal) followed by 1, it should increase the code size
  1280.     read from the input stream to the next bit size.  No
  1281.     blocking of the codes is performed, so the next code at
  1282.     the increased size should be read from the input stream
  1283.     immediately after where the previous code at the smaller
  1284.     bit size was read.  Again, the decompressor should not
  1285.     increase the code size used until the sequence 256,1 is
  1286.     encountered.
  1287.  
  1288. 2)  When the table becomes full, total clearing is not
  1289.     performed.  Rather, when the compressor emits the code
  1290.     sequence 256,2 (decimal), the decompressor should clear
  1291.     all leaf nodes from the Ziv-Lempel tree, and continue to
  1292.     use the current code size.  The nodes that are cleared
  1293.     from the Ziv-Lempel tree are then re-used, with the lowest
  1294.     code value re-used first, and the highest code value
  1295.     re-used last.  The compressor can emit the sequence 256,2
  1296.     at any time.
  1297.  
  1298.  
  1299.  
  1300. Expanding - Methods 2-5
  1301. -----------------------
  1302.  
  1303. The Reducing algorithm is actually a combination of two
  1304. distinct algorithms.  The first algorithm compresses repeated
  1305. byte sequences, and the second algorithm takes the compressed
  1306. stream from the first algorithm and applies a probabilistic
  1307. compression method.
  1308.  
  1309. The probabilistic compression stores an array of 'follower
  1310. sets' S(j), for j=0 to 255, corresponding to each possible
  1311. ASCII character.  Each set contains between 0 and 32
  1312. characters, to be denoted as S(j)[0],...,S(j)[m], where m<32.
  1313. The sets are stored at the beginning of the data area for a
  1314. Reduced file, in reverse order, with S(255) first, and S(0)
  1315. last.
  1316.  
  1317. The sets are encoded as { N(j), S(j)[0],...,S(j)[N(j)-1] },
  1318. where N(j) is the size of set S(j).  N(j) can be 0, in which
  1319. case the follower set for S(j) is empty.  Each N(j) value is
  1320. encoded in 6 bits, followed by N(j) eight bit character values
  1321. corresponding to S(j)[0] to S(j)[N(j)-1] respectively.  If
  1322. N(j) is 0, then no values for S(j) are stored, and the value
  1323. for N(j-1) immediately follows.
  1324.  
  1325. Immediately after the follower sets, is the compressed data
  1326. stream.  The compressed data stream can be interpreted for the
  1327. probabilistic decompression as follows:
  1328.  
  1329.  
  1330. let Last-Character <- 0.
  1331. loop until done
  1332.     if the follower set S(Last-Character) is empty then
  1333.         read 8 bits from the input stream, and copy this
  1334.         value to the output stream.
  1335.     otherwise if the follower set S(Last-Character) is non-empty then
  1336.         read 1 bit from the input stream.
  1337.         if this bit is not zero then
  1338.             read 8 bits from the input stream, and copy this
  1339.             value to the output stream.
  1340.         otherwise if this bit is zero then
  1341.             read B(N(Last-Character)) bits from the input
  1342.             stream, and assign this value to I.
  1343.             Copy the value of S(Last-Character)[I] to the
  1344.             output stream.
  1345.  
  1346.     assign the last value placed on the output stream to
  1347.     Last-Character.
  1348. end loop
  1349.  
  1350.  
  1351. B(N(j)) is defined as the minimal number of bits required to
  1352. encode the value N(j)-1.
  1353.  
  1354.  
  1355. The decompressed stream from above can then be expanded to
  1356. re-create the original file as follows:
  1357.  
  1358.  
  1359. let State <- 0.
  1360.  
  1361. loop until done
  1362.     read 8 bits from the input stream into C.
  1363.     case State of
  1364.         0:  if C is not equal to DLE (144 decimal) then
  1365.                 copy C to the output stream.
  1366.             otherwise if C is equal to DLE then
  1367.                 let State <- 1.
  1368.  
  1369.         1:  if C is non-zero then
  1370.                 let V <- C.
  1371.                 let Len <- L(V)
  1372.                 let State <- F(Len).
  1373.             otherwise if C is zero then
  1374.                 copy the value 144 (decimal) to the output stream.
  1375.                 let State <- 0
  1376.  
  1377.         2:  let Len <- Len + C
  1378.             let State <- 3.
  1379.  
  1380.         3:  move backwards D(V,C) bytes in the output stream
  1381.             (if this position is before the start of the output
  1382.             stream, then assume that all the data before the
  1383.             start of the output stream is filled with zeros).
  1384.             copy Len+3 bytes from this position to the output stream.
  1385.             let State <- 0.
  1386.     end case
  1387. end loop
  1388.  
  1389.  
  1390. The functions F,L, and D are dependent on the 'compression
  1391. factor', 1 through 4, and are defined as follows:
  1392.  
  1393. For compression factor 1:
  1394.     L(X) equals the lower 7 bits of X.
  1395.     F(X) equals 2 if X equals 127 otherwise F(X) equals 3.
  1396.     D(X,Y) equals the (upper 1 bit of X) * 256 + Y + 1.
  1397. For compression factor 2:
  1398.     L(X) equals the lower 6 bits of X.
  1399.     F(X) equals 2 if X equals 63 otherwise F(X) equals 3.
  1400.     D(X,Y) equals the (upper 2 bits of X) * 256 + Y + 1.
  1401. For compression factor 3:
  1402.     L(X) equals the lower 5 bits of X.
  1403.     F(X) equals 2 if X equals 31 otherwise F(X) equals 3.
  1404.     D(X,Y) equals the (upper 3 bits of X) * 256 + Y + 1.
  1405. For compression factor 4:
  1406.     L(X) equals the lower 4 bits of X.
  1407.     F(X) equals 2 if X equals 15 otherwise F(X) equals 3.
  1408.     D(X,Y) equals the (upper 4 bits of X) * 256 + Y + 1.
  1409.  
  1410.  
  1411. Imploding - Method 6
  1412. --------------------
  1413.  
  1414. The Imploding algorithm is actually a combination of two distinct
  1415. algorithms.  The first algorithm compresses repeated byte
  1416. sequences using a sliding dictionary.  The second algorithm is
  1417. used to compress the encoding of the sliding dictionary output,
  1418. using multiple Shannon-Fano trees.
  1419.  
  1420. The Imploding algorithm can use a 4K or 8K sliding dictionary
  1421. size. The dictionary size used can be determined by bit 1 in the
  1422. general purpose flag word; a 0 bit indicates a 4K dictionary
  1423. while a 1 bit indicates an 8K dictionary.
  1424.  
  1425. The Shannon-Fano trees are stored at the start of the compressed
  1426. file. The number of trees stored is defined by bit 2 in the
  1427. general purpose flag word; a 0 bit indicates two trees stored, a
  1428. 1 bit indicates three trees are stored.  If 3 trees are stored,
  1429. the first Shannon-Fano tree represents the encoding of the
  1430. Literal characters, the second tree represents the encoding of
  1431. the Length information, the third represents the encoding of the
  1432. Distance information.  When 2 Shannon-Fano trees are stored, the
  1433. Length tree is stored first, followed by the Distance tree.
  1434.  
  1435. The Literal Shannon-Fano tree, if present is used to represent
  1436. the entire ASCII character set, and contains 256 values.  This
  1437. tree is used to compress any data not compressed by the sliding
  1438. dictionary algorithm.  When this tree is present, the Minimum
  1439. Match Length for the sliding dictionary is 3.  If this tree is
  1440. not present, the Minimum Match Length is 2.
  1441.  
  1442. The Length Shannon-Fano tree is used to compress the Length part
  1443. of the (length,distance) pairs from the sliding dictionary
  1444. output.  The Length tree contains 64 values, ranging from the
  1445. Minimum Match Length, to 63 plus the Minimum Match Length.
  1446.  
  1447. The Distance Shannon-Fano tree is used to compress the Distance
  1448. part of the (length,distance) pairs from the sliding dictionary
  1449. output. The Distance tree contains 64 values, ranging from 0 to
  1450. 63, representing the upper 6 bits of the distance value.  The
  1451. distance values themselves will be between 0 and the sliding
  1452. dictionary size, either 4K or 8K.
  1453.  
  1454. The Shannon-Fano trees themselves are stored in a compressed
  1455. format. The first byte of the tree data represents the number of
  1456. bytes of data representing the (compressed) Shannon-Fano tree
  1457. minus 1.  The remaining bytes represent the Shannon-Fano tree
  1458. data encoded as:
  1459.  
  1460.     High 4 bits: Number of values at this bit length + 1. (1 - 16)
  1461.     Low  4 bits: Bit Length needed to represent value + 1. (1 - 16)
  1462.  
  1463. The Shannon-Fano codes can be constructed from the bit lengths
  1464. using the following algorithm:
  1465.  
  1466. 1)  Sort the Bit Lengths in ascending order, while retaining the
  1467.     order of the original lengths stored in the file.
  1468.  
  1469. 2)  Generate the Shannon-Fano trees:
  1470.  
  1471.     Code <- 0
  1472.     CodeIncrement <- 0
  1473.     LastBitLength <- 0
  1474.     i <- number of Shannon-Fano codes - 1   (either 255 or 63)
  1475.  
  1476.     loop while i >= 0
  1477.         Code = Code + CodeIncrement
  1478.         if BitLength(i) <> LastBitLength then
  1479.             LastBitLength=BitLength(i)
  1480.             CodeIncrement = 1 shifted left (16 - LastBitLength)
  1481.         ShannonCode(i) = Code
  1482.         i <- i - 1
  1483.     end loop
  1484.  
  1485.  
  1486. 3)  Reverse the order of all the bits in the above ShannonCode()
  1487.     vector, so that the most significant bit becomes the least
  1488.     significant bit.  For example, the value 0x1234 (hex) would
  1489.     become 0x2C48 (hex).
  1490.  
  1491. 4)  Restore the order of Shannon-Fano codes as originally stored
  1492.     within the file.
  1493.  
  1494. Example:
  1495.  
  1496.     This example will show the encoding of a Shannon-Fano tree
  1497.     of size 8.  Notice that the actual Shannon-Fano trees used
  1498.     for Imploding are either 64 or 256 entries in size.
  1499.  
  1500. Example:   0x02, 0x42, 0x01, 0x13
  1501.  
  1502.     The first byte indicates 3 values in this table.  Decoding the
  1503.     bytes:
  1504.             0x42 = 5 codes of 3 bits long
  1505.             0x01 = 1 code  of 2 bits long
  1506.             0x13 = 2 codes of 4 bits long
  1507.  
  1508.     This would generate the original bit length array of:
  1509.     (3, 3, 3, 3, 3, 2, 4, 4)
  1510.  
  1511.     There are 8 codes in this table for the values 0 thru 7.  Using the
  1512.     algorithm to obtain the Shannon-Fano codes produces:
  1513.  
  1514.                                   Reversed     Order     Original
  1515. Val  Sorted   Constructed Code      Value     Restored    Length
  1516. ---  ------   -----------------   --------    --------    ------
  1517. 0:     2      1100000000000000        11       101          3
  1518. 1:     3      1010000000000000       101       001          3
  1519. 2:     3      1000000000000000       001       110          3
  1520. 3:     3      0110000000000000       110       010          3
  1521. 4:     3      0100000000000000       010       100          3
  1522. 5:     3      0010000000000000       100        11          2
  1523. 6:     4      0001000000000000      1000      1000          4
  1524. 7:     4      0000000000000000      0000      0000          4
  1525.  
  1526.  
  1527. The values in the Val, Order Restored and Original Length columns
  1528. now represent the Shannon-Fano encoding tree that can be used for
  1529. decoding the Shannon-Fano encoded data.  How to parse the
  1530. variable length Shannon-Fano values from the data stream is beyond the
  1531. scope of this document.  (See the references listed at the end of
  1532. this document for more information.)  However, traditional decoding
  1533. schemes used for Huffman variable length decoding, such as the
  1534. Greenlaw algorithm, can be successfully applied.
  1535.  
  1536. The compressed data stream begins immediately after the
  1537. compressed Shannon-Fano data.  The compressed data stream can be
  1538. interpreted as follows:
  1539.  
  1540. loop until done
  1541.     read 1 bit from input stream.
  1542.  
  1543.     if this bit is non-zero then       (encoded data is literal data)
  1544.         if Literal Shannon-Fano tree is present
  1545.             read and decode character using Literal Shannon-Fano tree.
  1546.         otherwise
  1547.             read 8 bits from input stream.
  1548.         copy character to the output stream.
  1549.     otherwise                   (encoded data is sliding dictionary match)
  1550.         if 8K dictionary size
  1551.             read 7 bits for offset Distance (lower 7 bits of offset).
  1552.         otherwise
  1553.             read 6 bits for offset Distance (lower 6 bits of offset).
  1554.  
  1555.         using the Distance Shannon-Fano tree, read and decode the
  1556.           upper 6 bits of the Distance value.
  1557.  
  1558.         using the Length Shannon-Fano tree, read and decode
  1559.           the Length value.
  1560.  
  1561.         Length <- Length + Minimum Match Length
  1562.  
  1563.         if Length = 63 + Minimum Match Length
  1564.             read 8 bits from the input stream,
  1565.             add this value to Length.
  1566.  
  1567.         move backwards Distance+1 bytes in the output stream, and
  1568.         copy Length characters from this position to the output
  1569.         stream.  (if this position is before the start of the output
  1570.         stream, then assume that all the data before the start of
  1571.         the output stream is filled with zeros).
  1572. end loop
  1573.  
  1574. Tokenizing - Method 7
  1575. --------------------
  1576.  
  1577. This method is not used by PKZIP.
  1578.  
  1579. Deflating - Method 8
  1580. -----------------
  1581.  
  1582. The Deflate algorithm is similar to the Implode algorithm using
  1583. a sliding dictionary of up to 32K with secondary compression
  1584. from Huffman/Shannon-Fano codes.
  1585.  
  1586. The compressed data is stored in blocks with a header describing
  1587. the block and the Huffman codes used in the data block.  The header
  1588. format is as follows:
  1589.  
  1590.    Bit 0: Last Block bit     This bit is set to 1 if this is the last
  1591.                              compressed block in the data.
  1592.    Bits 1-2: Block type
  1593.       00 (0) - Block is stored - All stored data is byte aligned.
  1594.                Skip bits until next byte, then next word = block length,
  1595.                followed by the ones compliment of the block length word.
  1596.                Remaining data in block is the stored data.
  1597.  
  1598.       01 (1) - Use fixed Huffman codes for literal and distance codes.
  1599.                Lit Code    Bits             Dist Code   Bits
  1600.                ---------   ----             ---------   ----
  1601.                  0 - 143    8                 0 - 31      5
  1602.                144 - 255    9
  1603.                256 - 279    7
  1604.                280 - 287    8
  1605.  
  1606.                Literal codes 286-287 and distance codes 30-31 are never
  1607.                used but participate in the huffman construction.
  1608.  
  1609.       10 (2) - Dynamic Huffman codes.  (See expanding Huffman codes)
  1610.  
  1611.       11 (3) - Reserved - Flag a "Error in compressed data" if seen.
  1612.  
  1613. Expanding Huffman Codes
  1614. -----------------------
  1615. If the data block is stored with dynamic Huffman codes, the Huffman
  1616. codes are sent in the following compressed format:
  1617.  
  1618.    5 Bits: # of Literal codes sent - 257 (257 - 286)
  1619.            All other codes are never sent.
  1620.    5 Bits: # of Dist codes - 1           (1 - 32)
  1621.    4 Bits: # of Bit Length codes - 4     (4 - 19)
  1622.  
  1623. The Huffman codes are sent as bit lengths and the codes are built as
  1624. described in the implode algorithm.  The bit lengths themselves are
  1625. compressed with Huffman codes.  There are 19 bit length codes:
  1626.  
  1627.    0 - 15: Represent bit lengths of 0 - 15
  1628.        16: Copy the previous bit length 3 - 6 times.
  1629.            The next 2 bits indicate repeat length (0 = 3, ... ,3 = 6)
  1630.               Example:  Codes 8, 16 (+2 bits 11), 16 (+2 bits 10) will
  1631.                         expand to 12 bit lengths of 8 (1 + 6 + 5)
  1632.        17: Repeat a bit length of 0 for 3 - 10 times. (3 bits of length)
  1633.        18: Repeat a bit length of 0 for 11 - 138 times (7 bits of length)
  1634.  
  1635. The lengths of the bit length codes are sent packed 3 bits per value
  1636. (0 - 7) in the following order:
  1637.  
  1638.    16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  1639.  
  1640. The Huffman codes should be built as described in the Implode algorithm
  1641. except codes are assigned starting at the shortest bit length, i.e. the
  1642. shortest code should be all 0's rather than all 1's.  Also, codes with
  1643. a bit length of zero do not participate in the tree construction.  The
  1644. codes are then used to decode the bit lengths for the literal and distance
  1645. tables.
  1646.  
  1647. The bit lengths for the literal tables are sent first with the number
  1648. of entries sent described by the 5 bits sent earlier.  There are up
  1649. to 286 literal characters; the first 256 represent the respective 8
  1650. bit character, code 256 represents the End-Of-Block code, the remaining
  1651. 29 codes represent copy lengths of 3 thru 258.  There are up to 30
  1652. distance codes representing distances from 1 thru 32k as described
  1653. below.
  1654.  
  1655.                              Length Codes
  1656.                              ------------
  1657.       Extra             Extra              Extra              Extra
  1658.  Code Bits Length  Code Bits Lengths  Code Bits Lengths  Code Bits Length(s)
  1659.  ---- ---- ------  ---- ---- -------  ---- ---- -------  ---- ---- ---------
  1660.   257   0     3     265   1   11,12    273   3   35-42    281   5  131-162
  1661.   258   0     4     266   1   13,14    274   3   43-50    282   5  163-194
  1662.   259   0     5     267   1   15,16    275   3   51-58    283   5  195-226
  1663.   260   0     6     268   1   17,18    276   3   59-66    284   5  227-257
  1664.   261   0     7     269   2   19-22    277   4   67-82    285   0    258
  1665.   262   0     8     270   2   23-26    278   4   83-98
  1666.   263   0     9     271   2   27-30    279   4   99-114
  1667.   264   0    10     272   2   31-34    280   4  115-130
  1668.  
  1669.                             Distance Codes
  1670.                             --------------
  1671.       Extra           Extra             Extra               Extra
  1672.  Code Bits Dist  Code Bits  Dist   Code Bits Distance  Code Bits Distance
  1673.  ---- ---- ----  ---- ---- ------  ---- ---- --------  ---- ---- --------
  1674.    0   0    1      8   3   17-24    16    7  257-384    24   11  4097-6144
  1675.    1   0    2      9   3   25-32    17    7  385-512    25   11  6145-8192
  1676.    2   0    3     10   4   33-48    18    8  513-768    26   12  8193-12288
  1677.    3   0    4     11   4   49-64    19    8  769-1024   27   12 12289-16384
  1678.    4   1   5,6    12   5   65-96    20    9 1025-1536   28   13 16385-24576
  1679.    5   1   7,8    13   5   97-128   21    9 1537-2048   29   13 24577-32768
  1680.    6   2   9-12   14   6  129-192   22   10 2049-3072
  1681.    7   2  13-16   15   6  193-256   23   10 3073-4096
  1682.  
  1683. The compressed data stream begins immediately after the
  1684. compressed header data.  The compressed data stream can be
  1685. interpreted as follows:
  1686.  
  1687. do
  1688.    read header from input stream.
  1689.  
  1690.    if stored block
  1691.       skip bits until byte aligned
  1692.       read count and 1's compliment of count
  1693.       copy count bytes data block
  1694.    otherwise
  1695.       loop until end of block code sent
  1696.          decode literal character from input stream
  1697.          if literal < 256
  1698.             copy character to the output stream
  1699.          otherwise
  1700.             if literal = end of block
  1701.                break from loop
  1702.             otherwise
  1703.                decode distance from input stream
  1704.  
  1705.                move backwards distance bytes in the output stream, and
  1706.                copy length characters from this position to the output
  1707.                stream.
  1708.       end loop
  1709. while not last block
  1710.  
  1711. if data descriptor exists
  1712.    skip bits until byte aligned
  1713.    check data descriptor signature
  1714.    read crc and sizes
  1715. endif
  1716.  
  1717. Decryption
  1718. ----------
  1719.  
  1720. The encryption used in PKZIP was generously supplied by Roger
  1721. Schlafly.  PKWARE is grateful to Mr. Schlafly for his expert
  1722. help and advice in the field of data encryption.
  1723.  
  1724. PKZIP encrypts the compressed data stream.  Encrypted files must
  1725. be decrypted before they can be extracted.
  1726.  
  1727. Each encrypted file has an extra 12 bytes stored at the start of
  1728. the data area defining the encryption header for that file.  The
  1729. encryption header is originally set to random values, and then
  1730. itself encrypted, using three, 32-bit keys.  The key values are
  1731. initialized using the supplied encryption password.  After each byte
  1732. is encrypted, the keys are then updated using pseudo-random number
  1733. generation techniques in combination with the same CRC-32 algorithm
  1734. used in PKZIP and described elsewhere in this document.
  1735.  
  1736. The following is the basic steps required to decrypt a file:
  1737.  
  1738. 1) Initialize the three 32-bit keys with the password.
  1739. 2) Read and decrypt the 12-byte encryption header, further
  1740.    initializing the encryption keys.
  1741. 3) Read and decrypt the compressed data stream using the
  1742.    encryption keys.
  1743.  
  1744.  
  1745. Step 1 - Initializing the encryption keys
  1746. -----------------------------------------
  1747.  
  1748. Key(0) <- 305419896
  1749. Key(1) <- 591751049
  1750. Key(2) <- 878082192
  1751.  
  1752. loop for i <- 0 to length(password)-1
  1753.     update_keys(password(i))
  1754. end loop
  1755.  
  1756.  
  1757. Where update_keys() is defined as:
  1758.  
  1759.  
  1760. update_keys(char):
  1761.   Key(0) <- crc32(key(0),char)
  1762.   Key(1) <- Key(1) + (Key(0) & 000000ffH)
  1763.   Key(1) <- Key(1) * 134775813 + 1
  1764.   Key(2) <- crc32(key(2),key(1) >> 24)
  1765. end update_keys
  1766.  
  1767.  
  1768. Where crc32(old_crc,char) is a routine that given a CRC value and a
  1769. character, returns an updated CRC value after applying the CRC-32
  1770. algorithm described elsewhere in this document.
  1771.  
  1772.  
  1773. Step 2 - Decrypting the encryption header
  1774. -----------------------------------------
  1775.  
  1776. The purpose of this step is to further initialize the encryption
  1777. keys, based on random data, to render a plaintext attack on the
  1778. data ineffective.
  1779.  
  1780.  
  1781. Read the 12-byte encryption header into Buffer, in locations
  1782. Buffer(0) thru Buffer(11).
  1783.  
  1784. loop for i <- 0 to 11
  1785.     C <- buffer(i) ^ decrypt_byte()
  1786.     update_keys(C)
  1787.     buffer(i) <- C
  1788. end loop
  1789.  
  1790.  
  1791. Where decrypt_byte() is defined as:
  1792.  
  1793.  
  1794. unsigned char decrypt_byte()
  1795.     local unsigned short temp
  1796.     temp <- Key(2) | 2
  1797.     decrypt_byte <- (temp * (temp ^ 1)) >> 8
  1798. end decrypt_byte
  1799.  
  1800.  
  1801. After the header is decrypted,  the last 1 or 2 bytes in Buffer
  1802. should be the high-order word/byte of the CRC for the file being
  1803. decrypted, stored in Intel low-byte/high-byte order, or the high-order
  1804. byte of the file time if bit 3 of the general purpose bit flag is set.
  1805. Versions of PKZIP prior to 2.0 used a 2 byte CRC check; a 1 byte CRC check is
  1806. used on versions after 2.0.  This can be used to test if the password
  1807. supplied is correct or not.
  1808.  
  1809.  
  1810. Step 3 - Decrypting the compressed data stream
  1811. ----------------------------------------------
  1812.  
  1813. The compressed data stream can be decrypted as follows:
  1814.  
  1815.  
  1816. loop until done
  1817.     read a character into C
  1818.     Temp <- C ^ decrypt_byte()
  1819.     update_keys(temp)
  1820.     output Temp
  1821. end loop
  1822.  
  1823.  
  1824. In addition to the above mentioned contributors to PKZIP and PKUNZIP,
  1825. I would like to extend special thanks to Robert Mahoney for suggesting
  1826. the extension .ZIP for this software.
  1827.  
  1828.  
  1829. References:
  1830.  
  1831.     Fiala, Edward R., and Greene, Daniel H., "Data compression with
  1832.        finite windows",  Communications of the ACM, Volume 32, Number 4,
  1833.        April 1989, pages 490-505.
  1834.  
  1835.     Held, Gilbert, "Data Compression, Techniques and Applications,
  1836.                     Hardware and Software Considerations",
  1837.        John Wiley & Sons, 1987.
  1838.  
  1839.     Huffman, D.A., "A method for the construction of minimum-redundancy
  1840.        codes", Proceedings of the IRE, Volume 40, Number 9, September 1952,
  1841.        pages 1098-1101.
  1842.  
  1843.     Nelson, Mark, "LZW Data Compression", Dr. Dobbs Journal, Volume 14,
  1844.        Number 10, October 1989, pages 29-37.
  1845.  
  1846.     Nelson, Mark, "The Data Compression Book",  M&T Books, 1991.
  1847.  
  1848.     Storer, James A., "Data Compression, Methods and Theory",
  1849.        Computer Science Press, 1988
  1850.  
  1851.     Welch, Terry, "A Technique for High-Performance Data Compression",
  1852.        IEEE Computer, Volume 17, Number 6, June 1984, pages 8-19.
  1853.  
  1854.     Ziv, J. and Lempel, A., "A universal algorithm for sequential data
  1855.        compression", Communications of the ACM, Volume 30, Number 6,
  1856.        June 1987, pages 520-540.
  1857.  
  1858.     Ziv, J. and Lempel, A., "Compression of individual sequences via
  1859.        variable-rate coding", IEEE Transactions on Information Theory,
  1860.        Volume 24, Number 5, September 1978, pages 530-536.
  1861.